#include<algorithm>
using namespace std;
class Solution {
    long long getCount(int prefix,int n) {
        long long cnt = 0;
        for (long long a = prefix, b = prefix + 1; a <= n; a *= 10, b *= 10)
            cnt += min(b, static_cast<long long>(n + 1)) - a;
        return cnt;
    }

public:
    int findKthNumber(int n, int k) {
        if (k == 1) return 1;
        long long p = 1;
        int prefix = 1;
        while (p < k) {
            long long cnt = getCount(prefix, n);
            if (p + cnt <= k) {
                p += cnt;
                prefix +=1;
            }
            else {
                p += 1;
                prefix *= 10;
            }
        }
        return prefix;
    }
};